package com.ztf0337.mycurriculumdesign.ui.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.ztf0337.mycurriculumdesign.R;
import com.ztf0337.mycurriculumdesign.Utils.TextDate;
import com.ztf0337.mycurriculumdesign.Utils.TimeConverters;
import com.ztf0337.mycurriculumdesign.Utils.TransitionUtils;
import com.ztf0337.mycurriculumdesign.entity.Order;
import com.ztf0337.mycurriculumdesign.service.OrderService;

public class OrderDetailActivity extends AppCompatActivity {

    private TextView tvOrderNumber, tvParkingSpaceNumber, tvParkLotName, tvPrice,tvType,
            tvLocation, tvStartTime, tvEndTime, tvTotalTime, tvTransactionStatus, tvLicencePlate;

    private ImageView btnBack;
    private OrderService orderService;

    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_detail);

        btnBack = findViewById(R.id.btnBack);
        btnBack.setOnClickListener(v -> {
            finish();
        });

        orderService = new OrderService(this);

        Intent intent = getIntent();
        Long id = intent.getLongExtra("id", -1L);

        tvOrderNumber = findViewById(R.id.tvOrderNumber);

        Order order = orderService.getOrderById(id);
        if (order == null) {
            Toast.makeText(this, "系统错误", Toast.LENGTH_SHORT).show();
            finish();
        }

        tvOrderNumber = findViewById(R.id.tvOrderNumber);
        tvOrderNumber.setText(order.getOrderNumber());

        tvParkingSpaceNumber = findViewById(R.id.tvParkingSpaceNumber);
        tvParkingSpaceNumber.setText(order.getParkingSpaceNumber());

        tvParkLotName = findViewById(R.id.tvParkLotName);
        tvParkLotName.setText(order.getParkLotName());

        tvPrice = findViewById(R.id.tvPrice);
        tvPrice.setText("￥" + order.getTotalPrice());

        tvType = findViewById(R.id.tvType);
        tvType.setText(TransitionUtils.transParkType(order.getParkType()));

        tvLocation = findViewById(R.id.tvLocation);
        tvLocation.setText(order.getLocation());

        tvStartTime = findViewById(R.id.tvStartTime);
        tvStartTime.setText(TimeConverters.format(order.getStartTime()));

        tvEndTime = findViewById(R.id.tvEndTime);
        if (order.getEndTime().equals(0L)) {
            tvEndTime.setText("未结算");
        } else {
            tvEndTime.setText(TimeConverters.format(order.getEndTime()));
        }


        tvTotalTime = findViewById(R.id.tvTotalTime);
        if (order.getTotalTime() == null) {
            tvTotalTime.setText("未结算");
        } else {
            tvTotalTime.setText(order.getTotalTime() + " 小时");
        }

        tvTransactionStatus = findViewById(R.id.tvTransactionStatus);
        tvTransactionStatus.setText(order.getTransactionStatus() ? "已结束" : "进行中");

        tvLicencePlate = findViewById(R.id.tvLicencePlate);
        tvLicencePlate.setText(order.getLicencePlate());

    }
}
